package test;

import java.io.File;

/**
 * 描述：
 * @author hl
 * @version 1.0
 * @date 2020/10/31 15:06
 */
public class FileSize {

    public static int getFileLenght(File dir){
        int len = 0;
        if (dir.isFile()) {
            len += dir.length();
        }else{
            File[] files = dir.listFiles();
            for (int i = 0; i < files.length; i++) {
                len += getFileLenght(files[i]);
            }
        }
        return  len;
    }

    public static void main(String[] args) {
        String path = "E:\\书";
        File file = new File(path);
        System.out.println(getFileLenght(file));
    }
}
